#pragma once

#include "aot_inet_config.h"
#include <interface/aot_inet_interface2.h>
#include <ace/Timer_Queue_T.h>
#include <ace/Synch.h>

class timer_queue_upcall;
typedef ACE_Timer_Queue_T<aot::inet::itimer_queue_event_handler*, timer_queue_upcall, ace_thread_mutex_type> timer_queue_type;

class timer_queue_upcall
{
public:
	timer_queue_upcall();
	 ~timer_queue_upcall();
public:
	/// The signature of this method changed at ACE 5.4. The 'recurring_timer'
	/// parameter was added.
	int timeout (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		const void *arg,
		int recurring_timer,
		const ACE_Time_Value &cur_time);

	/// This method is called when the timer queue is destroyed and
	/// the timer is still contained in it.
	int deletion (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		const void *arg);

	/// The following methods don't appear before ACE 5.4, so aren't
	/// referenced in APG (it's based on ACE 5.3).

	/// This method is called when a timer is registered.
	int registration (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		const void *arg);

	/// This method is called before the timer expires.
	int preinvoke (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		const void *arg,
		int recurring_timer,
		const ACE_Time_Value &cur_time,
		const void *&upcall_act);

	/// This method is called after the timer expires.
	int postinvoke (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		const void *arg,
		int recurring_timer,
		const ACE_Time_Value &cur_time,
		const void *upcall_act);

	/// This method is called when a handler is cancelled
	int cancel_type (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		int dont_call,
		int &requires_reference_counting);

	/// This method is called when a timer is cancelled
	int cancel_timer (timer_queue_type &timer_queue,
		aot::inet::itimer_queue_event_handler *handler,
		int dont_call,
		int requires_reference_counting);
};
